package org.jimmy.tang.designpattern.behavior.iterator;

/**
 * @author jimmy
 * 
 */
public class ListImpl implements List {
    private Object[] list;

    private int index;

    private int size;

    public ListImpl() {
        index = 0;
        size = 0;
        list = new Object[100];
    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.List#iterator()
     */
    @Override
    public Iterator iterator() {
        return new IteratorImpl(this);

    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.List#get(int)
     */
    @Override
    public Object get(int index) {
        return list[index];
    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.List#getSize()
     */
    @Override
    public int getSize() {
        return size;
    }

    /* (non-Javadoc)
     * @see org.jimmy.tang.designpattern.behavior.iterator.List#add(java.lang.Object)
     */
    @Override
    public void add(Object obj) {
        list[index++] = obj;
        size++;
    }

}
